package server.exchange;

import java.io.Serializable;
import java.util.Date;

public class Order implements Serializable{
	private String client;
	private Operationtype operationType;
	private Orderstatus status=Orderstatus.PENDING;
	private String stockName;
	private int numberOfShares;
	private int id;
	float price;
	public Date date;
	
	public Order(String client, Operationtype operationType, String stockName,
			int numberOfShares, float price,int id) {
		super();
		this.client = client;
		this.operationType = operationType;
		this.stockName = stockName;
		this.numberOfShares = numberOfShares;
		this.price = price;
		this.id=id;
		this.date=new Date();
	}
	
	public Order(String client, Operationtype operationType, String stockName,
			int numberOfShares, float price,int id, Orderstatus status) {
		super();
		this.client = client;
		this.operationType = operationType;
		this.stockName = stockName;
		this.numberOfShares = numberOfShares;
		this.price = price;
		this.id=id;
		this.status=status;
		this.date=new Date();
	}
	
	public Order(String client, String stockName, int id, Orderstatus status) {
		this.client=client;
		this.stockName=stockName;
		this.id=id;
		this.status=status;
	}

	public int getId(){
		return this.id;
	}
	public Operationtype getOpperationType(){
		return this.operationType;
	}
	public int getNumberOfShares(){
		return this.numberOfShares;
	}
	public void getNShares(int n){
		this.numberOfShares-=n;
	}


	
	public String getStockName() {
		return stockName;
	}
	
	public String getClientName(){
		return this.client;
	}


	public Orderstatus getStatus() {
		return status;
	}

	public void setStatus(Orderstatus status) {
		this.status = status;
	}
	
	public boolean isCorrect(){
		boolean fl=true;
		if (this.price<=0) fl=false;
		if (this.numberOfShares<1) fl=false;
		return fl;
	}
	
	public Order getMyself(){
		return new Order(this.client, this.operationType, this.stockName, this.numberOfShares, this.price, this.id, this.status);
	}
	
	public String toString() {
		return "\n	id: " + this.getId() +
			   "\n	Name: " + this.getStockName() +
			   "\n	Date: " + this.getDate() +
			   "\n	Number: " + this.getNumberOfShares() +
			   "\n	Price " + this.getPrice() + "\n";
	}
	
	

	public float getPrice() {
		return price;
	}

	public Date getDate() {
		return date;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null){
			return false;
		} else if (! ( obj instanceof Order ) ){
			return false;
		} else {
			return ( this.getId() == ((Order)obj).getId() &&
					this.getStockName() == ((Order)obj).getStockName());	
		}
	}


	
	
	
}
